package com.eas.ereceipt.network;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface.OnCancelListener;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;
import com.eas.ereceipt.R;

public class NetworkUtility {
	
	private static ProgressDialog prDialog;

	public static final int DEFAULT_GET_TIME_OUT = 5000;
	public static final int DEFAULT_POST_TIME_OUT = 25000;
	
	//interface
	public static final String LOGIN = "Login";
	public static final String REGISTER = "Register";
	public static final String FORGOT_PASSWORD = "FORGOT_PASSWORD";
	public static final String CHANGE_PASSWORD = "CHANGE_PASSWORD";
	public static final String UPDATE_INFO = "UPDATE_INFO";
	public static final String UPLOAD_RECEIVE = "UPLOAD_RECEIVE";
	public static final String REPORT_RECEIVE = "REPORT_RECEIVE";
	
	//request @param
	public static String ACCOUNT_ID="AccountID";
	public static String USER_NAME="UserName";
	public static String PASSWORD="Password";
	public static String CURRENT_PASSWORD="CurrentPassword";
	public static String NEW_PASSWORD="NewPassword";
	public static String EMAIL="Email";
	public static String FULL_NAME="FullName";
	public static String GENDER="Gender";
	public static String FLIE_UPLOAD="FileUpload";
	public static String START_DATE="StartDate";
	public static String END_DATE="EndDate";
	public static String OPTION="Option";
	
	//response @param
	public static String MESS="mess";
	public static String RESULT_CODE="result_code";
	public static String RESULT_CODE_OK = "Ok";
	public static String RESULT_CODE_ERROR = "Error";
	public static String TAG="tag";
	public static String USER_INFO="user_info";
	public static String ID="ID";
	public static String IMAGES="Images";
	public static String REPORT_INFO = "report_info";
	public static String RECEPIT_ID = "ReceiveID";
	public static String TITLE = "Title";
	public static String MONEY = "money";
	public static String DESCRIPTION = "Description";
	public static String THUMB_URL = "ThumbUrl";
	public static String IMAGE_URL = "ImageUrl";
	public static String STATUS = "Status";
	public static String DATE_CREATE = "DateReceive";
	
	//helper function
	public static void showNoInternetToast(Context c){
		Toast.makeText(c, R.string.no_internet_toast_msg, Toast.LENGTH_SHORT).show();
	}
	
	public static void showConnectionErrorToast(Context c){
		Toast.makeText(c, R.string.connect_timed_out_toast_msg, Toast.LENGTH_SHORT).show();
	}
	
	public static void showProgressDialog(Context c,String title, String msg, boolean cancelable, OnCancelListener cancelListener){
		prDialog = ProgressDialog.show(c, title, msg, true, cancelable, cancelListener);
	}
	
	public static void dismissProgressDialog(){
		prDialog.dismiss();
	}
	
	public static boolean checkNetworkState(Context context){
		ConnectivityManager conMgr =  (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo i = conMgr.getActiveNetworkInfo();
		  if (i == null)
		    return false;
		  if (!i.isConnected())
		    return false;
		  if (!i.isAvailable())
		    return false;
		return true;
	}
	
}
